package com.spring.service.person.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.web.formbean.person.PersonBasicForm;
import com.spring.bean.person.PersonBasic;
import com.spring.dao.person.PersonBasicDao;
import com.spring.bean.page.Page;
import com.spring.bean.page.PageView;
import com.spring.service.ServiceSupport;
import com.spring.service.person.PersonBasicService;
import com.spring.exception.ServiceException;

@Service
@Transactional
public class PersonBasicServiceImpl extends ServiceSupport implements PersonBasicService {

	@Autowired
	private PersonBasicDao personBasicDao;

	/** insert */
	public boolean insert(PersonBasicForm personBasicForm) throws ServiceException {
		try{
			PersonBasic personBasic = formToEntity(PersonBasic.class, personBasicForm);
			return personBasicDao.insert(personBasic);
		} catch (Exception e) {
			throw new ServiceException("PersonBasic --- insert error", e);
		}
	}

	/** update */
	public boolean update(PersonBasicForm personBasicForm) throws ServiceException {
		try{
			PersonBasic personBasic = formToEntity(PersonBasic.class, personBasicForm);
			return personBasicDao.update(personBasic);
		} catch (Exception e) {
			throw new ServiceException("PersonBasic --- update error", e);
		}
	}

	/** delete */
	public boolean delete(Integer id) throws ServiceException {
		try{
			return personBasicDao.delete(id);
		} catch (Exception e) {
			throw new ServiceException("PersonBasic --- delete error", e);
		}
	}

	/** getById */
	public PersonBasic getById(Integer id) throws ServiceException {
		try{
			return personBasicDao.getById(id);
		} catch (Exception e) {
			throw new ServiceException("PersonBasic --- query by id error", e);
		}
	}

	/** queryForList */
	public List<PersonBasic> queryForList() throws ServiceException {
		try{
			return personBasicDao.queryForList();
		} catch (Exception e) {
			throw new ServiceException("PersonBasic --- query list error", e);
		}
	}

	/** queryForPage */
	public PageView<PersonBasic> queryForPage(Page page) throws ServiceException {
		try{
			return personBasicDao.queryForPage(page);
		} catch (Exception e) {
			throw new ServiceException("PersonBasicForm ---query page error", e);
		}
	}
}